package com.cnxjs.shs4et.controller;

import com.cnxjs.shs4et.common.Result;
import com.cnxjs.shs4et.entity.Comment;
import com.cnxjs.shs4et.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    // 按照帖子和发布时间查所有评论
    @GetMapping("/submitTime")
    public Result getAllComments(@RequestParam int commentTopic,
                                 @RequestParam(defaultValue = "true") boolean isDesc) {
        return commentService.findAll(commentTopic, isDesc);
    }

    // 按照帖子和点赞数量降序查看所有评论
    @GetMapping("/like")
    public Result getAllCommentsByLike(@RequestParam int commentTopic){
        return commentService.findAllByLike(commentTopic);
    }

    // 发表评论
    @PostMapping("/add")
    public Result add(@RequestBody Comment comment){
        return commentService.add(comment);
    }

    // 伪删除评论
    @DeleteMapping("/delete/{commentId}")
    public Result delete(@PathVariable int commentId){
        return commentService.delete(commentId);
    }
}
